package cn.mxb.logic.action;


import java.io.IOException;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ghs.jms.ConnUtils;
import com.ghs.jms.MessageReceiver;
import com.ghs.jms.MessageSender;
import com.ghs.jms.SendEmail;
import com.ghs.jms.SystemSettings;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import antlr.collections.List;
import cn.mxb.floor.web.BaseAction;
import cn.mxb.logic.entity.SysUser;
import cn.mxb.logic.service.ILoginService;
import cn.mxb.logic.service.ISysUserService;

public class LoginAction extends BaseAction implements Preparable,ModelDriven {
	protected static final String LOGIN_JSP = "/Login.jsp";
	protected static final String MAIN_JSP = "/WEB-INF/page/main.jsp";
	
	private SysUser sysUser;
	@Autowired
	private ILoginService loginService;
	@Autowired
	private ISysUserService sysUserService;
	

	/**
	 * 登录
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String login(){   
		try{ 
        
			System.out.println("登录");   
			
			SysUser user = loginService.findByProperty("userId", sysUser.getUserId());
			if(sysUser.getUserPwd().equals(user.getUserPwd())){
				
			    getRequest().getSession().setAttribute("userName",user.getUserName());
				ActionContext.getContext().getSession().put("sysUser", user);
				
				
				setForwardView(MAIN_JSP);
				return SUCCESS;
			}else{
				setForwardView(LOGIN_JSP);
				return SUCCESS;
			}
		}catch(Exception e){
			System.out.println(e);
		}
		setForwardView(LOGIN_JSP);
		return SUCCESS;
	}
	
	
	
	@Override
	public Object getModel() {
		return sysUser;
	}

	@Override
	public void prepare() throws Exception {
		if(sysUser == null){
			sysUser = new SysUser();
		}
	}

	public SysUser getSysUser() {
		return sysUser;
	}

	public void setSysUser(SysUser sysUser) {
		this.sysUser = sysUser;
	}

	public ILoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(ILoginService loginService) {
		this.loginService = loginService;
	}
	
}
